package com.zhx.io;

import java.io.IOException;
import java.net.Socket;
import java.util.Date;

/**
 * @author zhanghaixuan
 * @version 1.0
 * date 2021/5/20-10:03 上午
 * description io 的客户端模拟
 */
public class IOClient {
    public static void main(String[] args) {
        new Thread(() -> {
            try {
                Socket socket = new Socket("127.0.0.1", 8000);
                while (true) {
                    try {
                        /**
                         * 每20秒往服务端发送一个时间+hello world
                         */
                        socket.getOutputStream().write((new Date() + ": hello world").getBytes());
                        Thread.sleep(2000);
                    } catch (Exception e) {
                    }
                }
            } catch (IOException e) {
            }
        }).start();
    }
}
